#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int n = nums.size(), sum = 0, len = INT_MAX;
        for (int left = 0, right = 0; right < n; right++)
        {
            sum += nums[right];
            while (sum >= target)//判断
            {
                len = min(len, right - left + 1);//更新结果
                sum -= nums[left++];//出窗口
            }
        }
        return len == INT_MAX ? 0 : len;
    }
};
int main()
{
    vector<int> v({ 2,3,1,2,4,3 });
    cout << Solution().minSubArrayLen(7, v) << endl;
	return 0;
}
/*
题目链接:https://leetcode.cn/problems/minimum-size-subarray-sum/description/
*/
